package cn.hsa.fqz.util;

import cn.hsa.fqz.task.service.dto.RecordDetailsDTO;
import com.google.common.collect.Lists;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description TODO
 * @ClassName DataUtils
 * @Author Liu.Jun
 * @Create 2022-07-21 9:13
 * @Version 1.0.0
 */
public class DataUtils {

    public static boolean stringIsEmpty(String res){
        return res == null || res.equals("");
    }

    public static String genSetString(Set<String> set){
        List<String> ls = Lists.newArrayList();
        for (String str:set) {
            ls.add(str);
        }
        Collections.sort(ls); //排序
        StringBuffer buffer = new StringBuffer();
        for (String str:ls) {
            buffer.append("'").append(str).append("'").append("||");
        }
        return buffer.toString().substring(0,buffer.lastIndexOf("||"));
    }

    public static boolean isInList(List<RecordDetailsDTO> list, RecordDetailsDTO detail){
        boolean result = false;
        if(list.size() == 0){
            return false;
        }else{
            for (RecordDetailsDTO r: list) {
                if(detail.getName().equals(r.getName())
                        &&detail.getCertno().equals(r.getCertno())
                        &&detail.getFixmedinsName().equals(r.getFixmedinsName())
                        &&detail.getBgTime().equals(r.getBgTime())
                        &&detail.getEdTime().equals(r.getEdTime())
                        &&detail.getJb().equals(r.getJb())){
                    return true;
                }
            }
        }
        return result;
    }

    public static boolean isInList(List<RecordDetailsDTO> list, RecordDetailsDTO detail,String subType){
        boolean result = false;
        if(list.size() == 0){
            return false;
        }else{
            for (RecordDetailsDTO r: list) {
                if("1".equals(subType) &&
                        detail.getName().equals(r.getName())
                        &&detail.getCertno().equals(r.getCertno())
                        &&detail.getFixmedinsName().equals(r.getFixmedinsName())
                        &&detail.getBgTime().equals(r.getBgTime())
                        &&detail.getJb().equals(r.getJb())){
                    return true;
                }
                if("2".equals(subType) &&
                        detail.getName().equals(r.getName())
                        &&detail.getCertno().equals(r.getCertno())
                        &&detail.getFixmedinsName().equals(r.getFixmedinsName())
                        &&detail.getEdTime().equals(r.getEdTime())
                        &&detail.getJb().equals(r.getJb())){
                    return true;
                }
            }
        }
        return result;
    }

    public static Integer getWeekendByDateTime(String dateString) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
        long time =  sf.parse(dateString).getTime();
        calendar.setTimeInMillis(time);
        int week= calendar.get(Calendar.WEEK_OF_YEAR);
        return week;
    }
}
